
package com.kyhd.audio.server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Import;

import com.kyhd.audio.config.JPAConfiguration;
import com.kyhd.audio.config.OSSConfig;
import com.kyhd.audio.config.PropertyConfig;
import com.kyhd.audio.config.RedisHaConfiguration;
import com.kyhd.audio.config.ServiceConfiguration;
import com.kyhd.audio.config.Swagger2;
import com.kyhd.audio.controller.AudioController;


@EnableAutoConfiguration()
@Configuration
@Import({ ServiceConfiguration.class,
    PropertyConfig.class,
	JPAConfiguration.class, 
	Swagger2.class,
//	RedisConfiguration.class,
	RedisHaConfiguration.class,
	OSSConfig.class,
//	QQWryConfiguration.class
	})
@ComponentScan(basePackages = { "com.kyhd.audio.controller" }, useDefaultFilters = false, //
        includeFilters = { @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = {
        		AudioController.class
                }) })

@ServletComponentScan(basePackages = { "com.kyhd.audio.controller.filter" })
public class AudioApp {

	public static int port = 9888;

	@Bean
	// https://wiki.eclipse.org/Jetty/Howto/High_Load#Thread_Pool
	public EmbeddedServletContainerFactory servletContainer() {
		JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
		factory.setPort(port);
		// factory.addServerCustomizers();

		return factory;
	}

	public static void main(String[] args) throws Exception {
		try {
			String portNumString = System.getProperty("port");
			if (portNumString != null) {
				port = Integer.parseInt(portNumString.trim());
			}
		} catch (Exception e) {
		}
		SpringApplication.run(AudioApp.class, args);

	}

}
